home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 7 / Night Owl Shareware (NOPV7)(Night Owl Publisher Inc.)(1992).bin / 038a / bash1_12.arj / BASH1-12.TAR / bash-1.12 / examples / functions / whence < prev    next >
Text File  |  1991-07-07  |  985b  |  64 lines

  1. #
  2. # An almost-ksh compatible `whence' command.  This is as hairy as it is 
  3. # because of the desire to exactly mimic ksh.
  4. # This depends somewhat on knowing the format of the output of the bash
  5. # `builtin type' command.
  6. #
  7. # Chet Ramey
  8. # chet@ins.CWRU.Edu
  9. #
  10.  
  11.  
  12. whence()
  13. {
  14.     local vflag
  15.     local path
  16.  
  17.     vflag=
  18.     path=
  19.     if [ "$#" = "0" ] ; then
  20.         echo "whence: argument expected"
  21.         return 1
  22.     fi
  23.     case "$1" in
  24.         -v) vflag=1
  25.             shift 1
  26.             ;;
  27.         -*) echo "whence: bad option: $1"
  28.             return 1
  29.             ;;
  30.          *) ;;
  31.     esac
  32.  
  33.     if [ "$#" = "0" ] ; then
  34.         echo "whence: bad argument count"
  35.         return 1
  36.     fi
  37.  
  38.     for cmd
  39.     do
  40.         if [ "$vflag" ]     ; then
  41.             echo $(builtin type $cmd | sed 1q)
  42.         else
  43.             path=$(builtin type -path $cmd)
  44.             if [ "$path" ] ; then
  45.                 echo $path
  46.             else
  47.                 case "$cmd" in
  48.                     /*) echo ""
  49.                         ;;
  50.                      *) case "$(builtin type -type $cmd)" in
  51.                         "") echo ""
  52.                             ;;
  53.                          *) echo "$cmd"
  54.                             ;;
  55.                         esac
  56.                         ;;
  57.                 esac
  58.             fi
  59.         fi
  60.     done
  61.     return 0
  62. }
  63.